﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using QLHocSinh.DAO;
using QLHocSinh.DTO;
using QLHocSinh.BUS;

namespace QLHocSinh.DAO
{
    public class HocSinhDAO
    {
        public static DataTable SelectAll()
        {
            string Sql = "SELECT * FROM HOCSINH";
            return Config.AccessHelper.ExecuteQuery(Sql);
        }
        public static bool Insert(HocSinhDTO hs)
        {
            try
            {
                string Sql = "INSERT INTO HOCSINH(HoTen, GioiTinh, NgaySinh, DiaChi, Email, MaLop) VALUES('" + hs.HoTen + "','" + hs.GioiTinh + "'," + hs.NgaySinh + ",'" + hs.DiaChi + "','" + hs.Email + "','" + hs.MaLop + "')";
                Config.AccessHelper.ExecuteNonQuery(Sql);
                return true;
            }
            catch { return false; }
        }
        public static bool InsertProc(HocSinhDTO hs)
        {
            try
            {
                Dictionary<string, object> para = new Dictionary<string, object>();
                para.Add("HoTen", hs.HoTen);
                para.Add("GioiTinh", hs.GioiTinh);
                para.Add("NgaySinh", hs.NgaySinh);
                para.Add("DiaChi", hs.DiaChi);
                para.Add("Email", hs.Email);
                para.Add("MaLop", hs.MaLop);
                Config.AccessHelper.ExecuteProcedure("ThemHocSinh", para);
                return true;
            }
            catch
            {
                return false;
            }
        }
        public static bool Update(HocSinhDTO hs)
        {
            try
            {
                string sql = "UPDATE HOCSINH SET HoTen = '" + hs.HoTen + "',GioiTinh = '" + hs.GioiTinh + "',NgaySinh = " + hs.NgaySinh + ",DiaChi = '" + hs.DiaChi + "'Email = '" + hs.Email + "'MaLop = '" + hs.MaLop + "'where MaHocSinh=" + hs.MaHocSinh;
                Config.AccessHelper.ExecuteNonQuery(sql);
                return true;
            }
            catch
            {
                return false;
            }
        }
        public static bool UpdateProc(HocSinhDTO hs)
        {
            try
            {
                Dictionary<string, object> para = new Dictionary<string, object>();
                para.Add("MaHocSinh", hs.MaHocSinh);
                para.Add("HoTen", hs.HoTen);
                para.Add("GioiTinh", hs.GioiTinh);
                para.Add("NgaySinh", hs.NgaySinh);
                para.Add("DiaChi", hs.DiaChi);
                para.Add("Email", hs.Email);
                para.Add("MaLop", hs.MaLop);
                Config.AccessHelper.ExecuteProcedure("SuaHocSinh", para);
                return true;
            }
            catch
            {
                return false;
            }
        }
        public static bool Delete(HocSinhDTO hs)
        {
            try
            {
                string sql = "DELETE FROM HOCSINH WHERE MaHocSinh=" + hs.MaHocSinh;
                Config.AccessHelper.ExecuteNonQuery(sql);
                return true;
            }
            catch
            {
                return false;
            }
        }
        public static bool DeleteProc(HocSinhDTO hs)
        {
            try
            {
                Dictionary<string, object> para = new Dictionary<string, object>();
                para.Add("MaHocSinh", hs.MaHocSinh);
                Config.AccessHelper.ExecuteProcedure("XoaHocSinh", para);
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}
